import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'role_admin_controller.dart';

class RoleAdminPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetX<RoleAdminController>(
        init: RoleAdminController(),
        builder: (controller) {
          return Scaffold(
            appBar: AppBar(title: Text('角色管理')),
            body: GridView.builder(
                itemCount: controller.roles.length,
                padding: EdgeInsets.all(10),
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    //横轴元素个数
                    crossAxisCount: 4,
                    //纵轴间距
                    mainAxisSpacing: 15.0,
                    childAspectRatio: 5,
                    //横轴间距
                    crossAxisSpacing: 15),
                itemBuilder: (BuildContext context, int index) {
                  //Widget Function(BuildContext context, int index)
                  return _itemLayout(index, controller);
                }),
          );
        });
  }

  _itemLayout(int index, RoleAdminController controller) {
    final item = controller.roles[index];
    return InkWell(
        onDoubleTap: () {},
        child: Container(
            color: Color(0xffE0EEF9),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text(
                  item.intro!,
                  style: TextStyle(
                      color: Colors.blue, fontWeight: FontWeight.bold),
                ),
                SizedBox(
                  height: 3,
                ),
              ],
            )));
  }
}
